package com.kaisu.blog.application.user.convert;

import com.kaisu.blog.application.user.dto.UserDTO;
import com.kaisu.blog.domain.user.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author kaisu
 */
@Component
public abstract class UserApplicationConvertDecorated implements UserApplicationConvert {
    @Autowired
    private UserApplicationConvert delegate;

    @Override
    public UserDTO toDTO(User domain) {
        UserDTO dto = delegate.toDTO(domain);
        dto.setFollowings(Objects.nonNull(domain.getFollowings()) ? (long) domain.getFollowings().size() : 0L);
        dto.setFollowers(Objects.nonNull(domain.getFollowers()) ? (long) domain.getFollowers().size() : 0L);
        return dto;
    }
}
